package z.t.b.db.meta;

import java.sql.Timestamp;
import java.util.Map;
import java.util.TreeMap;

/**
 * xx
 *
 * @Description TODO
 * @Author ztb
 * @Date 2024/3/23 11:48
 * @Version 1.0
 */
public class Table {

    public static String _TYPE_TABLE = "TABLE";
    public static String _TYPE_VIEW = "VIEW";

    private String tableSchema;
    private String tableName;
    private String tableComment;
    private String objectType = "TABLE";
    private Timestamp createTime;

    private Map<String, Column> columns;
    private Map<String, Index> indexes;

    private String createDDL;

    private DB owner;

    public Table(DB owner) {
        columns = new TreeMap<>();
        indexes = new TreeMap<>();
        this.owner = owner;
    }

    public DB getOwner() {
        return owner;
    }

    public String getTableSchema() {
        return tableSchema;
    }

    public void setTableSchema(String tableSchema) {
        this.tableSchema = tableSchema;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String getTableComment() {
        return tableComment;
    }

    public void setTableComment(String tableComment) {
        this.tableComment = tableComment;
    }

    public String getObjectType() {
        return objectType;
    }

    public void setObjectType(String objectType) {
        this.objectType = objectType;
    }

    public Timestamp getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Timestamp createTime) {
        this.createTime = createTime;
    }

    public Map<String, Column> getColumns() {
        return columns;
    }

    public void setColumns(Map<String, Column> columns) {
        this.columns = columns;
    }

    public void addColumn(Column column){
        this.columns.put(column.getName(), column);
    }

    public Column getColumn(String columnName){
        return columns.get(columnName);
    }

    public Map<String, Index> getIndexes() {
        return indexes;
    }

    public void setIndexes(Map<String, Index> indexes) {
        this.indexes = indexes;
    }

    public void addIndex(Index index){
        this.indexes.put(index.getIndexName(), index);
    }

    public String getCreateDDL() {
        return createDDL;
    }

    public void setCreateDDL(String createDDL) {
        this.createDDL = createDDL;
    }
}
